// Device/pages/Bind/Verify/components/fail-component/index.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        componentData: {
            default: {},
            type: Object
        }
    },
    observers: {
        'componentData': function (value) {
            if (value) {
                this.data.room_category_options.forEach(item => {
                    if (item.value == String(value['room_category'])) {
                        value['room_category'] = item;
                    }
                });
                this.data.sensitivity_options.forEach(item => {
                    if (item.value == value['sensitivity']) {
                        value['sensitivity'] = item;
                    }
                });
                this.setData({
                    ...value
                })
            }
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        room_category: null,
        height: 150,
        stay: 0.1,
        sensitivity: null,
        ota_upgrades: 0,
        dianyun: 0,
        picker_show: false,
        columns: [],
        pickerType: null,
        room_category_options: [{
            label: '客厅',
            value: '1001'
        }, {
            label: '卧室',
            value: '2001'
        }, {
            label: '厨房',
            value: '3001'
        }, {
            label: '卫生间',
            value: '4001'
        }, {
            label: '阳台',
            value: '5001'
        }, {
            label: '储藏间',
            value: '6001'
        }],
        sensitivity_options: [{
            label: '标准',
            value: 2
        }, {
            label: '灵敏',
            value: 1
        }],
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onShowPicker(e) {
            this.setData({
                picker_show: true,
                columns: this.data[`${e.currentTarget.dataset.type}_options`],
                pickerType: e.currentTarget.dataset.type
            })
        },
        onPickerCancel() {
            this.setData({
                [`${this.data.pickerType}`]: null,
                picker_show: false
            })
        },
        onPickerConfirm(e) {
            this.setData({
                [`${this.data.pickerType}`]: e.detail.value,
                picker_show: false
            })
        },
        onStepChange(e) {
            this.setData({
                [`${e.currentTarget.dataset.type}`]: e.detail
            })
        },
        onDxChange(e) {
            this.setData({
                [`${e.currentTarget.dataset.type}`]: e.detail
            })
        },
        onChange(e) {
            const {
                type
            } = e.currentTarget.dataset;
            this.setData({
                [`${type}`]: !this.data[`${type}`]
            })
        },
        onNavigate() {
            this.triggerEvent('navigate')
        }
    }
})